package com.atguigu.daijia.payment.config;

import jakarta.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

public class RequestUtils {

  /**
   * 从HttpServletRequest对象中读取请求体数据。
   *
   * @param request HttpServletRequest对象
   * @return 请求体中的数据字符串
   * @throws IOException 如果读取过程中发生IO异常
   */
  public static String readData(HttpServletRequest request) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader reader = request.getReader();

    String line;
    while ((line = reader.readLine()) != null) {
      sb.append(line);
    }

    reader.close();
    return sb.toString();
  }
}